var t = getApp(), e = t.requirejs('core');
Page({
    data: {
        list: [],
        page: 1,
        isEnd: false
    },
    onLoad() {
        this.getList()
    },
    getList() {
        var that=this;
        if (that.data.isEnd){
            return ;
        }
        e.get("lottery/get_list", {page: this.data.page}, res => {
            console.log(res);
            if(res.error==0){
                let list = that.data.list;
                this.data.page == 1 && (list = []);
                for (let i = 0; i < res.list.length; i++) {
                    list.push(res.list[i])
                }
                this.setData({list})
                res.list.length < res.pagesize && this.setData({
                    isEnd: true
                })
            }else{
                wx.showToast({
                    title: res.message,
                    icon: 'none'
                })
            }
            
        })
    },
    onReachBottom() {
        !this.data.isEnd && this.setData({
            page: this.data.page + 1
        }), this.getList();
    },
    button(s) {
        let data = s.currentTarget.dataset, list = this.data.list;
        e.get("lottery.zitifahuo", data, res => {
            if(res.error == 1) {
                for (const index in list) {
                    if(list[index].log_id == data.id) {
                        list[index].isziti = data.isziti
                    }
                }
                this.setData({list})
            }
            wx.showToast({
                title: res.message,
                icon: 'none'
            })
        })
    }
})